﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Shop.Core.Share;
using Shop.IServices.Admin;
using Shop.Model.Dto.Admin.JurMunu;
using Shop.Model.View.Admin.JurMunu;
using Shop.Model.View.Admin.JurUser;

namespace Shop.AdminApi.Controllers;

/// <summary>
/// 菜单服务
/// </summary>
[ApiController]
[Route("admin/[controller]")]
public class JurMunuController: ShopControllerBase
{
    private readonly IJurMunuService _jurMunuService;
    private readonly IUserContext _userContext;
    /// <summary>
    /// 菜单服务
    /// </summary>
    /// <param name="jurMunuService"></param>
    /// <param name="userContext"></param>
    public JurMunuController(IJurMunuService jurMunuService, IUserContext userContext)
    { 
        _jurMunuService = jurMunuService;
        _userContext = userContext;
    }
    
    /// <summary>
    /// 添加菜单
    /// </summary>
    /// <param name="dto"></param>
    /// <returns></returns>
    [HttpPost("Add")]
    [Authorize("Permission")]
    public async Task<AppResult> AddMenu(MenuAddDto dto)
    {
        try
        {
            return await _jurMunuService.AddMenu(dto);
        }
        catch (Exception ex)
        {
            return Problem(ex.Message.ToString());
        }
    }

    /// <summary>
    /// 查询菜单
    /// </summary>
    /// <returns></returns>
    [HttpGet("List")]
    [Authorize("Permission")]
    public async Task<AppResult<List<MenuListVo>>> GetMenuList()
        => await _jurMunuService.GetMenuList();

    /// <summary>
    /// 菜单树
    /// </summary>
    /// <returns></returns>
    [HttpGet("Tree")]
    public async Task<AppResult<MenuTreeVo[]>> GetMenuTree()
        => await _jurMunuService.GetMenuTree();

    /// <summary>
    /// 编辑菜单
    /// </summary>
    /// <param name="dto"></param>
    /// <returns></returns>
    [HttpPost("Modify")]
    [Authorize("Permission")]
    public async Task<AppResult> Modify(MenuModifyDto dto)
    {
        try
        {
            return await _jurMunuService.Modify(dto);
        }
        catch (Exception ex)
        {
            return Problem(ex.Message.ToString());
        }
        
    }

    /// <summary>
    /// 获取文件夹列表
    /// </summary>
    /// <returns></returns>
    [HttpGet("FileTree")]
    public async Task<AppResult<SimpleTreeVo<long>[]>> GetFileList()
        => await _jurMunuService.GetFileList();

    /// <summary>
    /// 删除
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpPost("Delete")]
    [Authorize("Permission")]
    public async Task<AppResult> Delete(SimpleDto<long> input)
    {
        try
        {
            return await _jurMunuService.Delete(input.Value);
        }
        catch (Exception ex)
        {
            return Problem(ex.Message.ToString());
        }
    }
}